package biz.impl;

import java.util.Date;
import java.util.List;

import biz.ProjectManagerBiz;
import dao.MissionsDao;
import dao.ProjectManagerDao;
import pojo.MissionRelations;
import pojo.Missions;
import pojo.ProjectMissions;
import pojo.Users;
import pojo.view.ProjectDynmic;
import pojo.view.ProjectUser;
import pojo.view.ScoreProjectUser;

public class ProjectManagerBizImpl implements ProjectManagerBiz {
	
	
//	private ProjectManagerDao projectManagerDao;
//	public ProjectManagerDao getProjectManagerDao() {
//		return projectManagerDao;
//	}
//
//
//
//	public void setProjectManagerDao(ProjectManagerDao projectManagerDao) {
//		this.projectManagerDao = projectManagerDao;
//	}
//
//	@Override
//	public List<Users> getAllProjectUserByProjectId(int projectid) {
//		// TODO Auto-generated method stub
//		return projectManagerDao.getAllProjectUserByProjectId(projectid);
//	}
//
//	
//
//	@Override
//	public List<Users> projectUserFenYe(int projectteamUserNowNo, int projectid) {
//		// TODO Auto-generated method stub
//		return projectManagerDao.projectUserFenYe(projectteamUserNowNo, projectid);
//	}
//
//	@Override
//	public int getProjectUserTotalNo(int projectid) {
//		// TODO Auto-generated method stub
//		int projectUserTotalNo=0;
//		List<Users> list=getAllProjectUserByProjectId(projectid);
//		if(list!=null){
//			int length=list.size();
//		if(length%4==0){
//			projectUserTotalNo=length/4;
//		}else{
//			projectUserTotalNo=length/4+1;
//		}
//		}
//		return projectUserTotalNo;
//	}
//
//	@Override
//	public List<ProjectMission> getAllProjectMissionByProjectId(int projectid) {
//		// TODO Auto-generated method stub
//		return projectManagerDao.getAllProjectMissionByProjectId(projectid);
//	}
//
//	@Override
//	public void addProjectMission(String missionName, String description, int urpid) {
//		projectManagerDao.addProjectMission(missionName,description,urpid);
//		
//	}



	



//	@Override
//	public ProjectMission getProjectMissionByProMisId(int projecmissiontid) {
//		// TODO Auto-generated method stub
//		return projectManagerDao.getProjectMissionByProMisId(projecmissiontid);
//	}
	
	private MissionsDao missionsDao;
	public MissionsDao getMissionsDao() {
		return missionsDao;
	}

	public void setMissionsDao(MissionsDao missionsDao) {
		this.missionsDao = missionsDao;
	}

	private ProjectManagerDao projectManagerDao;
	public ProjectManagerDao getProjectManagerDao() {
		return projectManagerDao;
	}

	public void setProjectManagerDao(ProjectManagerDao projectManagerDao) {
		this.projectManagerDao = projectManagerDao;
	}

	@Override
	public List<Users> getAllProjectUserByProjectId(int projectid) {
		// TODO Auto-generated method stub
		return projectManagerDao.getAllProjectUserByProjectId(projectid);
	}

	@Override
	public List<Users> projectUserFenYe(int projectteamUserNowNo, int projectid) {
		// TODO Auto-generated method stub
		return projectManagerDao.projectUserFenYe(projectteamUserNowNo, projectid);
	}

	@Override
	public int getProjectUserTotalNo(int projectid) {
		// TODO Auto-generated method stub
		int projectUserTotalNo=0;
		List<Users> list=getAllProjectUserByProjectId(projectid);
		if(list!=null){
			int length=list.size();
		if(length%4==0){
			projectUserTotalNo=length/4;
		}else{
			projectUserTotalNo=length/4+1;
		}
		}
		return projectUserTotalNo;
	}

	@Override
	public List<ProjectMissions> getAllProjectMissionByProjectId(int projectid) {
		// TODO Auto-generated method stub
		return projectManagerDao.getAllProjectMissionByProjectId(projectid);
	}


	@Override
	public ProjectMissions getProjectMissionByProMisId(int projecmissiontid) {
		// TODO Auto-generated method stub
		return projectManagerDao.getProjectMissionByProMisId(projecmissiontid);
	}

	@Override
	public void addRelationalTable(MissionRelations mr) {
		// TODO Auto-generated method stub
		projectManagerDao.addRelationalTable(mr);
	}

	@Override
	public void addProjectMissionAndGetId(ProjectMissions projectmission) {
		// TODO Auto-generated method stub
		projectManagerDao.addProjectMissionAndGetId(projectmission);
	}

	@Override
	public int getUrpIdByProMisId(int projectmissiontid) {
		// TODO Auto-generated method stub
		return projectManagerDao.getUrpIdByProMisId(projectmissiontid);
	}

	@Override
	public int getProjectIdByUrpId(int urpid) {
		// TODO Auto-generated method stub
		return projectManagerDao.getProjectIdByUrpId(urpid);
	}

	@Override
	public List<Missions> getAllMissionByProMisId(int projectmissiontid) {
		// TODO Auto-generated method stub
		return projectManagerDao.getAllMissionByProMisId(projectmissiontid);
	}

	@Override
	public void addMissionAndGetId(String missionName, String description, Date timestamp, int urpid,
			int projectmissiontid) {
		// TODO Auto-generated method stub
		projectManagerDao.updatePMtoUnCompleted(projectmissiontid);
		projectManagerDao.addMissionAndGetId(missionName, description, timestamp, urpid, projectmissiontid);
	}

	@Override
	public List<ProjectUser> getAllUsersByProjectId(int projectid) {
		// TODO Auto-generated method stub
		return projectManagerDao.getAllUsersByProjectId(projectid);
	}

	@Override
	public int getUrpIdByUidAndPid(int userid, int projectid) {
		// TODO Auto-generated method stub
		return projectManagerDao.getUrpIdByUidAndPid(userid,projectid);
	}

	@Override
	public ScoreProjectUser getScoreUserByUrpId(int urpid) {
		
//		int completedMissionNB=projectManagerDao.getComMissionByUrpid(urpid).length();
		// TODO Auto-generated method stub
		
		return projectManagerDao.getScoreUserByUrpId(urpid);
	}

	@Override
	public void scoreProMember(int urpid, int subjectivescore) {
		// TODO Auto-generated method stub
		projectManagerDao.scoreProMember(urpid,subjectivescore);
	}

	@Override
	public String getPrograsePersent(String projectid) {		
		try {
			System.out.println("biz获取已完成阶段任务所需的projectid和分别是"+projectid);
			List<ProjectMissions> pmList1= missionsDao.findProjectMissionsIsCPByUrpid(projectid, "2");
			List<ProjectMissions> pmList2= missionsDao.findProjectMissionsByUrpid(projectid, "2");
			//DecimalFormat df = new DecimalFormat("#.00");
			if(pmList1.isEmpty()||pmList2.isEmpty()){
				System.out.println("进度条的biz没取到值");
				System.out.println("pmList1的大小是"+pmList1.size()+"  pmList2的大小是"+pmList2.size());
				return "0";
			}else{
				System.out.println("pmList1的大小是"+pmList1.size()+"  pmList2的大小是"+pmList2.size());
				System.out.println("获得的百分比是"+Integer.valueOf(100*pmList1.size()/pmList2.size()));
				return String.valueOf(Integer.valueOf(100*pmList1.size()/(pmList2.size()-2)));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}


	/*@Override
	public int getProjectUserTotalNo() {
		// TODO Auto-generated method stub
		int projectUserTotalNo=0;
		List<Users> list=getAllProjectUserByProjectId();
		if(list!=null){
			int length=list.size();
		if(length%4==0){
			projectUserTotalNo=length/4;
		}else{
			projectUserTotalNo=length/4+1;
		}
		}
		return projectUserTotalNo;
	}
	@Override
	public List<Users> getAllProjectUserByProjectId() {
		// TODO Auto-generated method stub
		return projectManagerDao.getAllProjectUserByProjectId();
	}*/
	
	@Override
	public List<ProjectDynmic> getAllProjectDynamic(int projectid) {
		// TODO Auto-generated method stub
		return projectManagerDao.getAllProjectDynamic(projectid);
	}
}
